
//去空格全局函数
const trimAll = function (ele) {
    if (typeof ele === 'string') {
        return ele.split(/[\t\r\f\n\s]*/g).join('');

    } else {
        console.error(`${typeof ele} is not the expected type, but the string type is expected`)
    }

}
// 年月日时分秒
const timeFormatOne = function (e) {
    let dt = new Date(e);
    var y = dt.getFullYear()
    var mt = (dt.getMonth() + 1).toString()
    var day = dt.getDate().toString()
    var h = dt.getHours().toString()
    var m = dt.getMinutes().toString()
    var s = dt.getSeconds().toString()
    // let timestamp = new Date(y, mt, day, h, m, s).getTime()
    // console.log(timestamp)
    return y + "年" + mt + "月" + day + "日" + h + ":" + m + ":" + s;
}
// 年月日
const timeFormatTwo = function (e) {
    let dt = new Date(e);
    var y = dt.getFullYear()
    var mt = (dt.getMonth() + 1).toString()
    var day = dt.getDate().toString()
    return y + "年" + mt + "月" + day + "日";
}

// 年月日时分
const timeFormatThree = function (e) {
    let dt = new Date(e);
    var y = dt.getFullYear()
    var mt = (dt.getMonth() + 1).toString()
    var day = dt.getDate().toString()
    var h = dt.getHours().toString()
    var m = dt.getMinutes().toString()
    var s = dt.getSeconds().toString()
    return y + "年" + mt + "月" + day + "日" + h + ":" + m;
}

const diffTime = function (startTime, endTime) {
    let newStartTime = startTime.toString() + " UTC+0800"
    let newEndTime = endTime.toString() + " UTC+0800"
    let stnum = new Date(newStartTime).getTime()
    let ednum = new Date(newEndTime).getTime()
    let now = new Date().getTime()
    //进行中
    if (now >= stnum && now <= ednum) {
        return 1
    }
    //未开始
    if (now < stnum) {
        return 0
    }
    // 已结束
    if (now > ednum) {
        return -1
    }
}

export default {
    trimAll,
    timeFormatOne,
    timeFormatTwo,
    timeFormatThree,
    diffTime
}